import * as React from "react";
import Link from "next/link";
import { Metadata } from "next";
import { getServerSession } from "next-auth/next";
import { authOptions } from "@/app/api/auth/[...nextauth]/route";
import { Button } from "@/components/ui/button";
import { LogIn } from "lucide-react";
import { Shell } from "@/components/shell";
import { VendorQuotationsTable } from "@/lib/techsales-rfq/vendor-response/table/vendor-quotations-table";
import { InformationButton } from "@/components/information/information-button"
export const metadata: Metadata = {
  title: "기술영업 해양HULL RFQ 관리",
  description: "기술영업 해양HULL RFQ를 관리합니다.",
};

export default async function VendorQuotationsHullPage() {
  // 세션 확인
  const session = await getServerSession(authOptions);

  if (!session?.user) {
    return (
      <Shell>
        <div className="flex min-h-[400px] flex-col items-center justify-center space-y-4">
          <div className="text-center">
            <h2 className="text-2xl font-bold tracking-tight">로그인이 필요합니다</h2>
            <p className="text-muted-foreground">
              RFQ를 확인하려면 로그인해주세요.
            </p>
          </div>
          <Button asChild>
            <Link href="/api/auth/signin">
              <LogIn className="mr-2 h-4 w-4" />
              로그인
            </Link>
          </Button>
        </div>
      </Shell>
    );
  }

  // 벤더 ID 확인 (사용자의 회사 ID가 벤더 ID)
  const vendorId = session.user.techCompanyId;
  if (!vendorId) {
    return (
      <Shell>
        <div className="flex min-h-[400px] flex-col items-center justify-center space-y-4">
          <div className="text-center">
            <h2 className="text-2xl font-bold tracking-tight">기술영업 벤더 정보가 없습니다</h2>
            <p className="text-muted-foreground">
              기술영업 벤더 정보가 없습니다. 관리자에게 문의하세요.
            </p>
          </div>
        </div>
      </Shell>
    );
  }

  return (
    <Shell variant="fullscreen" className="h-full">
      {/* 고정 헤더 영역 */}
      <div className="flex-shrink-0">
        <div className="flex-shrink-0 flex flex-col gap-4 md:flex-row md:items-center md:justify-between">
          <div>
            <div className="flex items-center gap-2">
              <h1 className="text-2xl font-bold tracking-tight">기술영업 해양HULL RFQ</h1>
              <InformationButton pagePath="partners/techsales/rfq-offshore-hull" />
            </div>
            <p className="text-muted-foreground">
              할당받은 해양HULL RFQ에 대한 견적서를 작성하고 관리합니다.
            </p>
          </div>
        </div>

        {/* 견적서 테이블 */}
        <div className="flex-1 min-h-0 overflow-hidden">
          <div className="h-full overflow-auto">
            <VendorQuotationsTable vendorId={vendorId.toString()} rfqType="HULL" />
          </div>
        </div>
      </div>
    </Shell>
  );
}
